using Runtime.Common.Interface;

namespace Runtime.DesignPattern
{
    public abstract class ChainofResponsibilityBase : IChainofResponsibility
    {
        protected ChainofResponsibilityBase()
        {
        }

        protected ChainofResponsibilityBase(IChainofResponsibility responsibility)
        {
            NextChainof = responsibility;
        }

        public virtual IChainofResponsibility NextChainof { get; set; }

        /// <summary>
        /// 当前责任链任务事件
        /// </summary>
        public virtual void Transmit()
        {
        }

        /// <summary>
        /// 启用下一个责任链
        /// </summary>
        public virtual void OnResponsibility()
        {
            if (NextChainof != null)
            {
                NextChainof.Transmit();
                NextChainof.OnResponsibility();
            }
        }
    }
}